﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using AMobiSDK;

namespace Sai_Se_Dung
{
    public partial class Option : PhoneApplicationPage
    {
        public static bool isOn = true;

        public Option()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            PlayBackgoundSound();

            AdManager.setWidgetCode("f2257ad5570a4a773a2edd33504ef3c2");//Bạn phải thay mã này bằng widgetCode của bạn
            AdManager advertisement = new AdManager();
            advertisement.OnNavigationTo(this, null, null, banner);
        }

        private void PlayBackgoundSound()
        {
            if (isOn == true)
            {
                mp3_option.AutoPlay = true;
                mp3_option.Play();
            }
            else
            {
                mp3_option.AutoPlay = false;
                mp3_option.Stop();
            }
        }

        private void btnON_Click(object sender, RoutedEventArgs e)
        {
            mp3_btn.Play(); //Play button effect sound
            isOn = false;
            mp3_option.AutoPlay = false;
            mp3_option.Stop();
        }

        private void btnOFF_Click(object sender, RoutedEventArgs e)
        {
            mp3_btn.Play(); //Play button effect sound
            isOn = true;
            mp3_option.AutoPlay = true;
            mp3_option.Play();
        }

        private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
        {
            PlayBackgoundSound();
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (Option.isOn == true)
            {
                mp3_btn.Play();
            }

            if (NavigationService.CanGoBack)
            {
                while (NavigationService.RemoveBackEntry() != null)
                {
                    NavigationService.RemoveBackEntry();
                }
            }
            NavigationService.Navigate(new Uri("/Menu.xaml", UriKind.Relative));
        }
    }
}